package com.company.gas.controller;

import com.company.gas.pojo.Facility;
import com.company.gas.service.IFacilityService;
import com.company.gas.util.StatusCode;
import com.company.gas.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
/**
 * @author: Li Guangdi
 *
 */
@RestController
@RequestMapping("/gas/facility")
@Api(tags = "设备管理相关接口")
public class FacilityController {

    @Autowired
    private IFacilityService iFacilityService;

    //查询全部设备
    @GetMapping("/queryFacilityList")
    @ApiOperation("查询全部设备")
    public List<Facility> queryFacilityList(){
        List<Facility> facilityList = iFacilityService.queryFacilityList();
        return facilityList;
    }

    //根据facId查询指定设备
    @GetMapping("/queryFacilityById")
    @ApiOperation("根据facId查询指定设备")
    public Facility queryFacilityById(@RequestParam(value = "设备ID") String facId){
        Facility facility = iFacilityService.queryFacilityById(facId);
        System.out.println(facility);
        return facility;
    }

    //添加一个设备
    @GetMapping("/addFacility")
    @ApiOperation("添加一个设备")
    public ResultVo addFacility(@RequestParam(value = "设备ID") String facId,@RequestParam(value = "设备名称") String facName,
                              @RequestParam(value = "所属燃气库ID") String baseId,
                           @RequestParam(value = "状态") Integer status,@RequestParam(value = "标识符") Integer flag,
                           @RequestParam(value = "创建者") String createBy,@RequestParam(value = "修改者") String modifyBy){
        int isAddFacility = iFacilityService.addFacility(facId,facName,baseId,status,flag,createBy,modifyBy);
        if(isAddFacility == 1){
            return new ResultVo(true, StatusCode.OK,"添加成功");
        }else {
            return new ResultVo(false,StatusCode.ERROR,"添加失败");
        }
    }

    //修改一个设备
    @GetMapping("/updateFacility")
    @ApiOperation("修改一个设备")
    public ResultVo updateFacility(@RequestParam(value = "设备ID") String facId,@RequestParam(value = "设备名称") String facName,
                                 @RequestParam(value = "所属燃气库ID") String baseId,
                              @RequestParam(value = "状态") Integer status,@RequestParam(value = "修改者") String modifyBy){
        int isUpdateFacility = iFacilityService.updateFacility(facId,facName,baseId,status,modifyBy);
        if(isUpdateFacility == 1){
            return new ResultVo(true, StatusCode.OK,"修改成功");
        }else {
            return new ResultVo(false,StatusCode.ERROR,"修改失败");
        }
    }

    //根据facId删除指定设备
    @GetMapping("/deleteFacility")
    @ApiOperation("根据facId删除指定设备")
    public ResultVo deleteFacility(@RequestParam(value = "设备ID") String facId){
        int isDeleteFacility = iFacilityService.deleteFacility(facId);
        if(isDeleteFacility == 1){
            return new ResultVo(true, StatusCode.OK,"删除成功");
        }else {
            return new ResultVo(false,StatusCode.ERROR,"删除失败");
        }
    }



}
